//必须带done回调 执行完成调用
export default function selectTableRows({ vm, action, done, additionalData }) {
  let tableIds = action.extension.tableId.value
  tableIds.forEach((tableId) => {
    if (tableId) {
      let _table = vm.vuiComponents[tableId]
      let _rowNumber = action.extension.rowNumber.value
      if (_table) {
        // 选中当前表格事件数据
        if (action.extension.useEventData && action.extension.useEventData.value && additionalData) {
          _table.self.setCheckboxRow(additionalData.data, true)
        } else {
          if (_rowNumber && _rowNumber.split(',')) {
            setTimeout(() => {
              let rows = []
              if (_rowNumber === 'all') {
                rows = _table.ref.getData()
              } else {
                _rowNumber.split(',').forEach((num) => {
                  let _info = _table.ref.getData(parseInt(num))
                  if (_info) {
                    rows.push(_info)
                  } else {
                    console.log(`没有找到对应row-${num}`)
                  }
                })
              }

              _table.self.setCheckboxRow(rows, true)
            }, 10)
          }
        }
      } else {
        console.log('默认选中表格数据-没有找到表格')
      }
    }
  })
  setTimeout(() => {
    done(null, {})
  }, 20)
}
